package io.kiki.sba.registry.server.metadata.multi.cluster.remote;

import io.kiki.sba.registry.common.model.multi.cluster.DataCenter;
import io.kiki.sba.registry.common.model.slot.Slots;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

@Setter
@Getter
public class RemoteClusterSlotSyncResponse implements Serializable {
    private static final long serialVersionUID = 1L;

    private final String metaLeader;

    private final long metaLeaderEpoch;

    /**
     * sync on meta leader
     */

    private final boolean syncOnLeader;

    /**
     * leader warmuped
     */

    private final boolean leaderWarmuped;

    /**
     * if slot table upgrade
     */

    private final boolean SlotsUpgrade;

    /**
     * slot table will be null if syncOnLeader=false or SlotsUpgrade=false
     */
    @Getter
    private final Slots slots;

    @Getter
    private final DataCenter dataCenter;

    public RemoteClusterSlotSyncResponse(String metaLeader, long metaLeaderEpoch, boolean syncOnLeader, boolean leaderWarmuped, boolean SlotsUpgrade, Slots slots, DataCenter dataCenter) {
        this.metaLeader = metaLeader;
        this.metaLeaderEpoch = metaLeaderEpoch;
        this.syncOnLeader = syncOnLeader;
        this.leaderWarmuped = leaderWarmuped;
        this.SlotsUpgrade = SlotsUpgrade;
        this.slots = slots;
        this.dataCenter = dataCenter;
    }

    public static RemoteClusterSlotSyncResponse wrongLeader(String metaLeader, long metaLeaderEpoch) {
        return new RemoteClusterSlotSyncResponse(metaLeader, metaLeaderEpoch, false, false, false, null, null);
    }

    public static RemoteClusterSlotSyncResponse leaderNotWarmuped(String metaLeader, long metaLeaderEpoch) {
        return new RemoteClusterSlotSyncResponse(metaLeader, metaLeaderEpoch, true, false, false, null, null);
    }

    public static RemoteClusterSlotSyncResponse notUpgrade(String metaLeader, long metaLeaderEpoch, DataCenter dataCenter) {
        return new RemoteClusterSlotSyncResponse(metaLeader, metaLeaderEpoch, true, true, false, null, dataCenter);
    }

    public static RemoteClusterSlotSyncResponse upgrade(String metaLeader, long metaLeaderEpoch, Slots slots, DataCenter dataCenter) {
        return new RemoteClusterSlotSyncResponse(metaLeader, metaLeaderEpoch, true, true, true, slots, dataCenter);
    }


}
